$(document).ready(function(){
    $("#form").validate({
        rules: {
            oldPassword: {
                required: true,
                rangelength: [6, 10]
            },
            newPassword: {
                required: true,
                rangelength: [6, 10]
            },
            confirmPassword: {
                required: true,
                equalTo: "#newPassword"
            }
        },
        messages: {
            oldPassword: {
                required: "请填写旧密码！",
                rangelength: "密码必须在6～10位！"
            },
            newPassword: {
                required: "请填写旧密码！",
                rangelength: "新密码必须在6～10位！"
            },
            confirmPassword: {
                required: "请再次确认密码！",
                equalTo: "两次输入密码不一致！"
            }
        },
        submitHandler: function(form){
            var data = $("#form").getFormData();
            console.log(data);
            $.post({url: "/cms/modifyPwd", data: data}, function(data){
                if(data.code == "0"){
                    swal("成功提示", "密码修改成功！", "success");
                    $("#oldPassword").val("");
                    $("#newPassword").val("");
                    $("#confirmPassword").val("");
                }else{
                    swal("错误提示", data.errorMsg, "error");
                };
            });
        }
    });


});